﻿//https://leetcode.cn/problems/hanota-lcci/?envType=problem-list-v2&envId=recursion

class Solution {
public:
    void hanota(vector<int>& A, vector<int>& B, vector<int>& C)
    {
        int n = A.size();
        dfs(A, B, C, n);
    }

    void dfs(vector<int>& A, vector<int>& B, vector<int>& C, int n)
    {
        //如果只有一个盘子，直接从A挪到C
        if (n == 1)
        {
            C.push_back(A.back());
            A.pop_back();
            return;
        }

        //先把A的n-1个盘子挪到B
        dfs(A, C, B, n - 1);
        //把A的最后一个盘子挪到C
        C.push_back(A.back());
        A.pop_back();
        //再把B上的n-1个盘子挪到C
        dfs(B, A, C, n - 1);
    }
};